function red() {
    console.log("red");
  }
  function green() {
    console.log("green");
  }
  function yellow() {
    console.log("yellow");
  }
 

  function light(fn,time){
    return new Promise(resolve=>{
        setTimeout(function(){
            fn()
            resolve()
        },time)
    })
  }
  

  function step(){
      Promise.resolve().then(()=>{
          return light(red,3000)
      }).then(()=>{
            return light(green,2000)
      }).then(()=>{
            return light(yellow,1000)
      }).then(()=>{
          step()
      })
  }
  step()